#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int main()
{
	////实现数组元素的逆置:
	//int arr[5] = { 1,3,2,5,4 };
	//cout << "数组逆置前的结果:";
	//for (int i = 0; i < 5; i++)
	//{
	//	cout << arr[i] << "  ";
	//}
	//cout << endl;
	////记录起始位置和结束位置:
	//int start = 0;//起始下标
	//int end = sizeof(arr) / sizeof(arr[0]) - 1;//结束下标
	////写循环:
	//for (start; start <= end;start++,end--)
	//{
	//	int temp = arr[start];
	//	arr[start] = arr[end];
	//	arr[end] = temp;
	//}
	//cout << "数组逆置后的结果:";
	//for (int j = 0; j < 5; j++)
	//{
	//	cout << arr[j] << "  ";
	//}

	////冒泡排序:
	////最常用的排序算法，对数组内元素进行排序
	////1.比较相邻的元素，如果第一个比第二个大就交换:
	//int arr[] = { 4,2,8,0,5,7,1,6,12,421,45,654,43,3,9 };
	//int end = sizeof(arr) / sizeof(arr[0]) - 1;
	//cout << "排序前的结果:";
	//for (int o = 0; o <= end; o++)
	//{
	//	cout <<arr[o]<< "  ";
	//}
	//cout << endl;

	//for (int j = end; j > 0; j--)
	//{
	//	for (int i = 0; i < end; i++)
	//	{
	//		int temp = arr[i];
	//		arr[i] > arr[i + 1] ? arr[i] = arr[i + 1], arr[i + 1] = temp : true;
	//	}
	//}
	//cout << "排序后的结果:";
	//for (int k = 0; k <= end; k++)
	//{
	//	cout << arr[k] << "  ";
	//}
	//cout << endl;

	////二维数组:
	////二维数组就是在一维数组上多加一个维度
	////定义方式:
	////1.数据类型 数组名[行数][列数]
	//int arr1[2][3];//两行三列
	//
	////2.数据类型 数组名[行数][列数]={{数据1，数据2}，{数据3，数据4}}  建议利用第二种更直观
	//int arr2[2][3] =
	//{
	//	{1,2,3},
	//	{4,5,6}
	//};

	////3.数据类型 数组名[行数][列数]={数据1，数据2，数据3，数据4}
	//int arr3[2][3] = { 1,2,3,4,5,6 };

	////4.数据类型 数组名[][列数]={数据1，数据2，数据3，数据4}
	//int arr4[][3] = { 1,2,3,4,5,6 };//每三列为一行，自动计算


	//二维数组应用案例:
	//考试成绩统计:
	
	//失败的表格:
	/*string namesub[4][4] =
	{
		{"\t","语文\t","数学\t","英语\t"},
		{"张三\t","\t","\t","\t"},
		{"李四\t","\t","\t","\t"},
		{"王五\t","\t","\t","\t"}
	};
	int scores[3][3] =
	{
		{100,100,100},
		{90,50,100},
		{60,70,80}
	};
	int hang1 = sizeof(namesub) / sizeof(namesub[0]);
	int lie1 = sizeof(namesub[0]) / sizeof(namesub[0][0]);
	int hang2 = sizeof(scores) / sizeof(scores[0]);
	int lie2 = sizeof(scores[0]) / sizeof(scores[0][0]);
	for (int i = 0; i < hang1; i++)
	{
		for (int j = 0; j < lie1; j++)
		{
			if (i >= 1 && j >= 1)
			{
				for (int i = 0; i < 1;i++)
				{
					for (int j = 0; j < lie2;j++)
					{
						cout << scores[i][j] << "\t";
					}
					cout << endl;
				}
			}
			cout << namesub[i][j];
		}
		cout << endl;
	}*/


	//成功的表格:
	
	//创建科目数组:
string sub[3] = { "语文","数学","英语" };
	//创建姓名数组:
string name[3] = { "张三","李四","王五" };
	//创建成绩数组:
int score[3][3] =
{
	{100,100,100},
	{90,80,70},
	{50,60,70}
};
	
	//打印第一行:
cout << "姓名\t";
for (int i = 0; i < 3; i++)
{
	cout << sub[i] << "\t";
}
cout << "总成绩" << endl;

	//打印后面的姓名以及成绩:
for (int i = 0; i < 3; i++)//打印行
{
	//每一行都要有姓名，最后需要有总成绩,现在这里创建总成绩的变量
	int sum = 0;
	cout << name[i] << "\t";
	for (int j = 0; j < 3; j++)//打印列（横着打）
	{
		cout << score[i][j] << "\t";//打印完姓名后要打印成绩
		sum += score[i][j];
	}
	cout << sum;//行末尾要输出总成绩
	cout << endl;//最后换行
}


	

	/*string name[3] = { "张三","李四","王五" };
	int scores[3][3] =
	{
		{100,100,100},
		{90,50,100},
		{60,70,80}
	};
	int namehang = sizeof(name) / sizeof(name[0]);
	int scoreshang = sizeof(scores) / sizeof(scores[0]);
	int scoreslie = sizeof(scores[0]) / sizeof(scores[0][0]);
	for (int i = 0; i < scoreshang; i++)
	{
		int sum=0;
		for (int j = 0; j < scoreslie; j++)
		{
			sum += scores[i][j];
		}
		cout << name[i] << "的总成绩为:" << sum << endl;
	}*/
	return 0;
	system("pause");
}